package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.SysSchoolClass;
import com.ruoyi.system.domain.SysSchoolStudent;
import com.ruoyi.system.mapper.SysSchoolClassMapper;
import com.ruoyi.system.mapper.SysSchoolStudentMapper;
import com.ruoyi.system.service.ISysSchoolStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysSchoolRepeaterMapper;
import com.ruoyi.system.domain.SysSchoolRepeater;
import com.ruoyi.system.service.ISysSchoolRepeaterService;

/**
 * 留级信息Service业务层处理
 * 
 * @author 杨皓焜
 * @date 2021-02-01
 */
@Service
public class SysSchoolRepeaterServiceImpl implements ISysSchoolRepeaterService 
{
    @Autowired
    private SysSchoolRepeaterMapper sysSchoolRepeaterMapper;
    @Autowired
    private ISysSchoolStudentService sysSchoolStudentService;
    @Autowired
    private SysSchoolClassMapper sysSchoolClassMapper;

    /**
     * 查询留级信息
     * 
     * @param id 留级信息ID
     * @return 留级信息
     */
    @Override
    public SysSchoolRepeater selectSysSchoolRepeaterById(Long id)
    {
        return sysSchoolRepeaterMapper.selectSysSchoolRepeaterById(id);
    }

    /**
     * 查询留级信息列表
     * 
     * @param sysSchoolRepeater 留级信息
     * @return 留级信息
     */
    @Override
    public List<SysSchoolRepeater> selectSysSchoolRepeaterList(SysSchoolRepeater sysSchoolRepeater)
    {
        return sysSchoolRepeaterMapper.selectSysSchoolRepeaterList(sysSchoolRepeater);
    }

    /**
     * 新增留级信息
     * 
     * @param sysSchoolRepeater 留级信息
     * @return 结果
     */
    @Override
    public int insertSysSchoolRepeater(SysSchoolRepeater sysSchoolRepeater)
    {
        Long studentId = sysSchoolRepeater.getStudentId();
        SysSchoolStudent student = sysSchoolStudentService.selectSysSchoolStudentById(studentId);
        SysSchoolClass classByName = sysSchoolClassMapper.selectSysSchoolClassByName(sysSchoolRepeater.getNewClass());
        student.setClassId(classByName.getId());
        sysSchoolStudentService.updateSysSchoolStudent(student);
        return sysSchoolRepeaterMapper.insertSysSchoolRepeater(sysSchoolRepeater);
    }

    /**
     * 修改留级信息
     * 
     * @param sysSchoolRepeater 留级信息
     * @return 结果
     */
    @Override
    public int updateSysSchoolRepeater(SysSchoolRepeater sysSchoolRepeater)
    {
        sysSchoolRepeater.setUpdateBy(SecurityUtils.getUsername());
        sysSchoolRepeater.setUpdateTime(DateUtils.getNowDate());
        return sysSchoolRepeaterMapper.updateSysSchoolRepeater(sysSchoolRepeater);
    }

    /**
     * 批量删除留级信息
     * 
     * @param ids 需要删除的留级信息ID
     * @return 结果
     */
    @Override
    public int deleteSysSchoolRepeaterByIds(Long[] ids)
    {
        return sysSchoolRepeaterMapper.deleteSysSchoolRepeaterByIds(ids);
    }

    /**
     * 删除留级信息信息
     * 
     * @param id 留级信息ID
     * @return 结果
     */
    @Override
    public int deleteSysSchoolRepeaterById(Long id)
    {
        return sysSchoolRepeaterMapper.deleteSysSchoolRepeaterById(id);
    }
}
